#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int a[N];
int b[N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	sort(a + 1, a + n + 1);
	LL ans = 0;
	/*for(int i=1;i<=n;i++){
		if(a[i]==a[1]||a[i]==a[2]||a[i]==a[3]){
			ans++;
		}
	}*/
	/*int m=0;
	for(int i=1;i<=n;i++){
		if(a[i]!=a[i-1]){
			b[++m]=a[i];
		}
	}
	for(int i=1;i<=n;i++){
		bool f=0;
		for(int j=1;j<=3;j++){
			if(a[i]==b[j]){
				ans++;
				f=1;
				break;
			}
		}
		if(!f)break;
	}*/
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] == a[1])cnt1++;
		else if (a[i] == a[2])cnt2++;
		else if (a[i] == a[3])cnt3++;
		else break;
	}
	LL res = 0;
	if (cnt && cnt2 && cnt3) res = cnt1 * (cnt2 - 1) * (cnt3 - 2) / 6;
	else if (cnt && cnt2)
		//LL res=cnt1*cnt2*cnt3;
		cout << res << endl;
	return 0;
}
